//
//  ZZXwebViewController.m
//  Travel
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "ZZXwebViewController.h"
#import "UMSocial.h"

@interface ZZXwebViewController () <UIWebViewDelegate, UMSocialUIDelegate>

@property (nonatomic, strong)UIWebView *webView;
@property (nonatomic, strong)UIActivityIndicatorView *activity;


@property (nonatomic, strong)UIView *vv;
@property (nonatomic, strong)UILabel *la;

@end

@interface ZZXwebViewController ()

@end

@implementation ZZXwebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self addScreenEdgePan];
    UIBarButtonItem *shareButton = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"share"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(shareAction)];
    
    NSArray *buttonArr = [[NSArray alloc]initWithObjects:shareButton, nil];
    self.navigationItem.rightBarButtonItems = buttonArr;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"leftBack"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backToLast)];
    
    [self createWebView];
    [self createActivity];
}


- (void)createWebView
{
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, -60, CWIDTH, CHEIGHT )];
    self.webView.delegate = self;
    self.webView.backgroundColor = [UIColor whiteColor];
    
    
    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:self.link]];
    [self.webView loadRequest:request];
    [self.view addSubview:self.webView];
    
    
}
- (void)createActivity
{
    self.activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    self.activity.color = [UIColor colorWithRed:0.18 green:0.63 blue:0.68 alpha:1];
    self.activity.center = self.view.center;
    //    self.activity.frame = CGRectMake(50, 250, 60, 60);
    [self.view addSubview:self.activity];
    
}

#pragma mark - 分享按钮触发方法
- (void)shareAction
{
    
    [UMSocialSnsService presentSnsIconSheetView:self appKey:@"563df2f7e0f55a98c6003737" shareText:[NSString stringWithFormat:@"分享:%@ %@", @"我分享了:", self.link]  shareImage:nil shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina, nil] delegate:self];
    
}



#pragma mark - 按钮触发方法
- (void)backToLast
{
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [self.activity startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [self.activity stopAnimating];
    CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue];
    self.webView.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, height );
}

#pragma mark-滑动手势1
- (void)addScreenEdgePan
{
    UIScreenEdgePanGestureRecognizer *screenEdgePan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(presentLeftMenuViewController:)];
    screenEdgePan.edges = UIRectEdgeLeft;
    [self.view addGestureRecognizer:screenEdgePan];
    [self.webView addGestureRecognizer:screenEdgePan];

    
}
#pragma mark-滑动手势2
-(void)presentLeftMenuViewController:(UIScreenEdgePanGestureRecognizer *)edge
{
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
